<?php

class FooterBox extends AbstractBox {
	protected $template = 'main/footer.tpl';
	
	protected function setup() {
		$partnerRepository = new PartnerRepository();
		$partnerRepository->setOrderBy(array('sorting' => 'asc'));
		$partners = $partnerRepository->getAll();
		$partnersCount = count($partners);
		$blockClass = 3;
		if ($partnersCount < 4) {
			$blockClass = 12 / $partnersCount;
		}
		MySmarty::assign('blockClass', $blockClass);
		$partnersBlocks = $this->createPartnersBlocks($partners);
		MySmarty::assign('partnersBlocks', $partnersBlocks);
		MySmarty::assign('partnersBlocksCount', count($partnersBlocks));
		
		$copyright = $startYear = 2012;
		if (date('Y') > $startYear) {
			$copyright .= ' - ' . date('Y');
		}
		MySmarty::assign('copyright', $copyright);
		
		$inquiry = new InquiryBox();
		MySmarty::assign('inquiryBox', $inquiry->render());
	}
	
	private function createPartnersBlocks($partners) {
		$partnersBlocks = array();
		$partnersPerBlock = 4;
		$blockId = 0;
		foreach ($partners as $partner) {
			$partnersBlocks[$blockId][] = $partner;
			if (count($partnersBlocks[$blockId]) == $partnersPerBlock) {
				$blockId++;
			}
		}
		return $partnersBlocks;
	}
}

?>